// custom-tab-bar/index.js
import { storeBindingsBehavior } from "mobx-miniprogram-bindings";
import { store } from "../store/store";


Component({
    options: {
      styleIsolation: 'shared'
    },
    behaviors: [storeBindingsBehavior],
    
    storeBindings: {
      store,
      fields: {
        sum: "sum",
        index:"index"
      },
      actions: {
        updateIndex: 'updateIndex'
      },
    },

    observers:{
      'sum': function(val){
        // 将store中的值赋给list[1].info
        this.setData({
          'list[1].info':val
        })
      },
      'index':function(val){
        console.log(val)
      }
    },
    /**
     * 组件的属性列表
     */
    properties: {

    },

    /**
     * 组件的初始数据
     */
    data: {
        // active: 0,
        istrue: true,
        "list":[
            {
              "pagePath": "/pages/home/home",
              "text": "首页",
              "iconPath": "/images/tabs/home.png",
              "selectedIconPath": "/images/tabs/home-active.png",
              "info": ''
            },
            {
              "pagePath": "/pages/message/message",
              "text": "消息",
              "iconPath": "/images/tabs/message.png",
              "selectedIconPath": "/images/tabs/message-active.png",
              "info": 2
            },
            {
              "pagePath": "/pages/contact/contact",
              "text": "联系人",
              "iconPath": "/images/tabs/contact.png",
              "selectedIconPath": "/images/tabs/contact-active.png",
              "info": ''
            }
          ]
    },

    /**
     * 组件的方法列表
     */
    methods: {
        onChange(event) {
            // event.detail为当前索引值
            this.updateIndex( event.detail );
            wx.switchTab({
              url: this.data.list[event.detail].pagePath,
            })
        },
    }
})
